<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%@page import="com.lmpop.trade.ts_category.*" %>
<%@page import="com.lmpop.trade.ts_categoryattr.*" %>
<%@page import="com.lmpop.trade.ti_brand.Ti_brandInfo" %>
<%@page import="com.lmpop.trade.tb_commpara.Tb_commparaInfo" %>
<%@page import="com.lmpop.trade.ts_memlevel.Ts_memlevelInfo" %>

<jsp:useBean id="randomId" class="com.lmpop.frame.util.RandomID" scope="page" />  

<html>
<%
	 
  String goods_id = randomId.GenTradeId();
  String class_attr = "";
  if (request.getParameter("class_attr") != null)
  {
      class_attr = request.getParameter("class_attr");
  }
  Ts_categoryInfo ts_categoryInfo = new Ts_categoryInfo();
  Map catMap = ts_categoryInfo.getCatClassMap("2");
  Ti_brandInfo  ti_brandInfo = new  Ti_brandInfo();
  Tb_commparaInfo tb_commparaInfo = new Tb_commparaInfo(); 
  Ts_memlevelInfo ts_memlevelInfo =new Ts_memlevelInfo();     
                                                            
  String brand_select =  ti_brandInfo.getBrandSelectByCatId(class_attr,""); 
  List memLevelList =ts_memlevelInfo.getMemLevelAll();  
  
  String s_cat_all = ts_categoryInfo.getSelCatByTLevel("2","1");
  String s_brand_all = ti_brandInfo.getBrandSelectAll(""); 
  String s_price_unit = tb_commparaInfo.getSelectItem("18","");                                      
                                                    
  String catAttr[] = class_attr.split("\\|");
  String cat_names ="";  
  if(!class_attr.equals(""))
  {
      String catIds[] =	class_attr.split("\\|");	
      for(String catId:catIds)
      {
         if(catMap!=null)
         {
             if(catMap.get(catId)!=null)
             {
              cat_names +=catMap.get(catId).toString()+" > ";                 
             }                  
         
         }                 
      }		    
	 }
  
  //-------- get cat attr  
  
  Ts_categoryattrInfo ts_categoryattrInfo = new Ts_categoryattrInfo();
	List attList = new ArrayList();
  if(!catAttr[catAttr.length-1].equals(""))
  {
    	attList = ts_categoryattrInfo.getListByClassId(catAttr[catAttr.length-1]);
  }  
  	 
  List attrValueList = new ArrayList();
	int attrsize = 0,valuesize = 0;
	String cust_id="",publish_user_id="";
	if(session.getAttribute("session_cust_id")!=null){
	     cust_id  =session.getAttribute("session_cust_id").toString();
	}
  if(session.getAttribute("session_user_id")!=null){
	     publish_user_id  =session.getAttribute("session_user_id").toString();
	}
  
  //out.print("===========>"+cust_id);                                
     
%>	
  <head>
    <title>新增商品</title>
	  <link href="/program/admin/index/css/style.css" rel="stylesheet" type="text/css">
    <link href="/program/admin/index/css/thickbox.css" rel="stylesheet" type="text/css">
    
    <!-- 
	  <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
		<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>
		<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ti_goodsInfo.js'></script>
		-->
		
		<script type="text/javascript" src="/js/jquery.js"></script>
    
    <script type="text/javascript" src="/js/thickbox.js"></script>
    
    <script type="text/javascript" src="js_goods.js"></script>
 
	<style>
  .button_css{height:25px; width:135px; font-size: 10pt; color: #fff; border: 1px #cabca3 solid; 
              background:url(/program/admin/index/images/an_01.gif) repeat-x; cursor:pointer;padding:0 3px 0 3px;}
                                                                                                                  
  .button_s_css{height:20px; width:55px; font-size: 12px; color: #fff; border: 1px #cabca3 solid; 
            background:url(/program/admin/index/images/an_01.gif) repeat-x; cursor:pointer;padding:0 3px 0 3px;}
 
 </style>
 
 

 </head>

<body>
	<h1>新增商品</h1>
	     
	<form action="/doTradeReg.do" method="post" name="addForm">
	 	<table width="100%" align="center" cellpadding="0" cellspacing="0" class="dl_so">
        <tr>
          <td width="9%" align="center"><img src="/program/admin/index/images/ban_01.gif" /></td>
          <td width="91%" align="left">
		  <h4>产品属性</h4>
		  <span>产品属性填写的越少，越容易流失被搜索到的机会！建议您尽可能完整填写！</span><br/>
		  </td>
        </tr>
      </table>
      <br/>
      
  <table width="100%" cellpadding="1" cellspacing="1" border="0" class="listtab">
		
				<tr>
					<td  colspan="4">
				   &nbsp;&nbsp;<img src="/program/admin/images/infotip.gif" border="0">&nbsp;&nbsp;<span style="font-size:14px;font-weight:bold;">基本信息</span>			</td>
		    </tr>

			<tr>
			<td align="right" width="20%">
				你选择的类目:			
			</td>
			<td  colspan="3">
			   <font color="red"><%=cat_names%></font> 
				 &nbsp;&nbsp;<input class="button_css" type="button" value ="返回，重新选择类目" onclick="window.location.href='addInfo.jsp'">	
			</td>
		</tr>
		
		<tr>
			<td colspan="4">			 		 					
			
			 <%
			      	if( attList != null && attList.size() > 0 ) {
								 attrsize = attList.size();
								 Hashtable attrmap = new Hashtable();
							 	 for( int i = 0; i < attrsize; i++ )
								 {
								 	 attrmap = ( Hashtable )attList.get(i);
									 String attr_id = "",attr_name = "",default_tag ="", con_type="",attrStr = "",isfill="";
									 if( attrmap.get("attr_id") != null )
									 {
									 	 attr_id = attrmap.get( "attr_id" ).toString();
									 }
									 if( attrmap.get("attr_name") != null )
									 {
									 	 attr_name = attrmap.get( "attr_name" ).toString();
									 }
									 if( attrmap.get("default_tag") != null )  // if fill in or not									 
									 {
									 	 default_tag = attrmap.get("default_tag" ).toString();
									 }
									 if( attrmap.get("con_type") != null )
									 {
									 	 con_type = attrmap.get( "con_type" ).toString();
									 }
									 if( default_tag.equals( "0" ))
									 {
									 	 isfill = " <span style='color:red;'>*</span>";
									 }
									
									 
						%>
						
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
			        <tr>
			          <td width="18%" height="35" align="right" style="background:#F9F9F9;">
			          	 &nbsp;<%=attr_name%><%=isfill%>
			          </td>
			          <td width="48%" style="background:#F9F9F9;">
			          	
			          								  
								  <input type="hidden" name="attr_id<%=i%>" id="attr_id<%=i%>" value="<%=attr_id%>" /> 
								  <input type="hidden" name="attr_name<%=i%>" id="attr_name<%=i%>" value="<%=attr_name%>" />
								  <input type="hidden" name="con_type<%=i%>" id="con_type<%=i%>" value="<%=con_type%>" />
								  <input type="hidden" name="default_tag<%=i%>" id="default_tag<%=i%>" value="<%=default_tag%>" />
			          	<%
			          			String attrValue = "";
											
										  if(con_type.equals("0"))
											{
											 	 
											 	 attrValue = ts_categoryattrInfo.getSelectItems(attr_id,"");
									     									
									%>	
											   <select class="input" name="attr_value<%=i%>" id="attr_value<%=i%>" style="height:20px;">
											   <option value="">请选择</option>
											   		 <%=attrValue%>
											   </select>
									<%			
											}
												
											if( con_type.equals( "1") )
											{
												 
									 %>
												<input class="input" maxlength="30" type="text" name="attr_value<%=i%>" id="attr_value<%=i%>"  value="" size="20" maxlength="100" />
									<%			
											}
											if( con_type.equals( "2") ){
											attrValueList = ts_categoryattrInfo.getListByPk( attr_id );
											if( attrValueList != null && attrValueList.size() > 0 ) 
											{
                           
                                                Hashtable valuemap = (Hashtable)attrValueList.get(0);
												String default_value="";                           
												if( valuemap.get("default_value") != null )
												{
													default_value = valuemap.get("default_value").toString();
												}
													  
                                                String attrValues[] =	default_value.split("\\|");												  
												valuesize = attrValues.length;
												for( int j = 0; j < valuesize; j++ ) 
												{
									     %>
												    <input class="input" type="checkbox" name="attr_value<%=i%>" id="attr_value<%=i%>_<%=j%>" value="<%=attrValues[j]%>" /><%=attrValues[j]%>	
												    									
											 <%	   
											    }
											 %>  	
											  
											  <input type="hidden" name="valuesize<%=i%>" id="valuesize<%=i%>" value="<%=valuesize%>" /> 

											  <%
											}
										}
									%>		
			          	
			            <span class="STYLE5"></span>
			          </td>
			          <td width="36%"></td>
					  	</tr>
			      </table>
			      <%		}
							 }
						%>
						
						  <input type="hidden" name="attrsize" id="attrsize" value="<%=attrsize%>" />
			    </td>
       </tr>
	     
     <tr>
			<td align="right" width="20%">
				 商品名称<font color="red">*</font>		
			</td>
			<td colspan="3">
				  <input type="text" name="goods_name" id="goods_name" size="62" maxlength="300" />
			 </td>
		</tr>
  
      <tr>
			<td align="right" width="20%">
				 商品关键字<font color="red">*</font>		
			</td>
			<td colspan="3">
				 <input type="text" name="keywords" id="keywords" size="62" maxlength="100" />
			 </td>
		</tr>
        
   <tr>
			  <td align="right" width="20%">商品编号<font color="red">*</font></td>	   
			  <td width="18%">
			     <input type="text" name="goods_no" id="goods_no" size="15" maxlength="15" />
			  </td>
			  <td width="12%" align="right">商品品牌:</td>
			  <td width="60%">
			     <select name="brand_id" id="brand_id">
			        <option value="">请选择</option>
			        <%=brand_select%>
			     </select>			  
			  </td>
	 </tr>
    
     <tr>
			<td align="right" width="20%">
				商品缩略图:			
			</td>
			<td colspan="3">
			 <jsp:include page="/program/inc/uploadImgInc.jsp">
					<jsp:param name="attach_root_id" value="<%=goods_id%>" />
					<jsp:param name="img_type" value="1" />
				</jsp:include>

			
			</td>
		</tr> 
    
    
   <tr>
			  <td align="right" width="20%">市场价<font color="red">*</font></td>	   
			  <td width="18%">
			     <input type="text" name="market_price" id="market_price" size="15" maxlength="10" onKeyUp="if(isNaN(value))this.value=''"/>
			  </td>
			  <td width="12%" align="right">进价<font color="red">*</font></td>
			  <td width="60%">
			        <input name="org_price" id="org_price" type="text" maxlength="10" size="15" onKeyUp="if(isNaN(value))this.value=''"/>
			  </td>
	 </tr>
    
    
     <tr>
			  <td align="right" width="20%">销售价<font color="red">*</font></td>	   
			  <td width="18%">
			   			  
           <input type="text" name="sale_price" id="sale_price" size="15" maxlength="10" onkeyup="if(isNaN(value))this.value='';else setAlllevelPrice()"/>
			  
			  
			  </td>
			  <td width="72%" colspan="2">
			  
        </td>
			 	
			 	</tr>
      
    <tr id="mb_p">
			<td align="right" width="20%">
				会员价格:			
			</td>
			<td colspan="3">
      			 
      			<table width="100%" border="0" cellspacing="0" cellpadding="0">
			        			          
			          
			        			          	 
      			 
      			 <%
        int level_num=0;			  
			  if(memLevelList !=null && memLevelList.size()>0){	
			  
              level_num=	memLevelList.size();		       
			        for(int i=0;i<memLevelList.size();i++){
              Hashtable lmap =(Hashtable)memLevelList.get(i);
              String user_class="",class_name="",discount=""; 
              if(lmap.get("user_class")!=null){
                    user_class =lmap.get("user_class").toString();             
              } 
              if(lmap.get("class_name")!=null){
                    class_name =lmap.get("class_name").toString();             
              }
              if(lmap.get("discount")!=null){
                    discount =lmap.get("discount").toString();             
              }           
			%>
		   
 <tr>
		   
		    <td width="18%" height="35" align="right" style="background:#F9F9F9;">
			       <%=class_name%>
			  </td>

			<input type="hidden" name="userLevelId<%=i%>" id="userLevelId<%=i%>"	value="<%=user_class%>" />
			<td width="48%" style="background:#F9F9F9;">

			<input type="text" name="userLevelDiscount<%=i%>" id="userLevelDiscount<%=i%>" value="<%=discount%>" size="4"
						maxlength="6"	onkeyup="setlevelPrice(<%=i%>)" />
			<input type="text" id="level_price<%=i%>" name="level_price" value="" size="12" disabled />
			 </td>
    
     <td width="36%"></td>
 
 	</tr>

			<%
			  }
			}
			%>
 </table>



			</td>
		</tr>
     
     	<input type="hidden" name="level_num" id="level_num" value="<%=level_num%>"/>        
            
      <tr>
			<td align="right" width="20%">
				是否为免运费商品:			
			</td>
			<td colspan="3">
			    <input type="radio" name="ship_fare" id="ship_fare1" value="1" />是	
			    <input type="radio" name="ship_fare" id="ship_fare2" value="0" checked />否	
			</td>
		</tr>
  
  
   <tr>
			 <td align="right" width="20%">赠送积分数<font color="red">*</font></td>	   
			  <td width="18%">
			     <input type="text" name="send_inter" id="send_inter" size="15" maxlength="10" onKeyUp="if(isNaN(value))this.value=''"/>
			  </td>
			  <td width="12%" align="right">积分购买数<font color="red">*</font></td>
			  <td width="60%">
			     <input name="buy_inter" id="buy_inter" type="text" maxlength="10" onKeyUp="if(isNaN(value))this.value=''"/>
			  </td>
	 </tr>
    
    
   <tr>
			 <td align="right" width="20%">商品重量<font color="red">*</font></td>	   
			  <td width="18%">
			     <input type="text" name="weight" id="weight" size="15" maxlength="10" onKeyUp="if(isNaN(value))this.value=''"/>
			     
<!--			     <font color="#666666">(克)</font>-->		     
			  </td>
			  <td width="12%" align="right">计价单位<font color="red">*</font></td>
			  <td width="60%">
          <select name="price_unit" id="price_unit">
            <option value="">请选择</option>
             <%=s_price_unit%>           
            </select>               			 
			  </td>
	  </tr>
    
 	<tr>
					<td  colspan="4">
				   &nbsp;&nbsp;<img src="/program/admin/images/infotip.gif" border="0">&nbsp;&nbsp;<span style="font-size:14px;font-weight:bold;">库存信息</span>			</td>
		    </tr>
    
    
    
    <tr>
			 <td align="right" width="20%">库存初始量<font color="red">*</font></td>	   
			  <td width="18%">
			     <input type="text" name="stock_in" id="stock_in" size="15" maxlength="10" onKeyUp="if(!/^[1-9][0-9]*$/.test(this.value))this.value=''" />
			  </td>
			  <td width="12%" align="right">最低库存量<font color="red">*</font></td>
			  <td width="60%">
			    <input name="stock_down" id="stock_down" type="text" maxlength="10" onKeyUp="if(!/^[1-9][0-9]*$/.test(this.value))this.value=''" />
			  </td>
	  </tr>
     
     <input name="stock_num" id="stock_num" type="hidden" value=""/>
     
     <input type="hidden" name="stock_out" id="stock_out" value="0"/>
     
     <tr>
			 <td align="right" width="20%">商品库存单价<font color="red">*</font></td>	   
			  <td width="18%">
			     <input type="text" name="one_price" id="one_price" size="15" maxlength="10" onKeyUp="if(isNaN(value))this.value=''"/>
			  </td>
			  <td width="12%" align="right"></td>
			  <td width="60%">
			    
			  </td>
	  </tr>
    
	<tr>
					<td  colspan="4">
				   &nbsp;&nbsp;<img src="/program/admin/images/infotip.gif" border="0">&nbsp;&nbsp;<span style="font-size:14px;font-weight:bold;">详细信息</span>			</td>
		    </tr>
       
  <tr>
			<td align="right" width="20%">
				商品概述:			
			</td>
			<td colspan="3">
			  <textarea name="outline" id="outline" cols="55" rows="6" maxlength="200" onkeyup="return isMaxLen(this)" onBlur="return isMaxLen(this)"></textarea>			
			</td>
		</tr>
		
		<tr>
			<td align="right" width="20%">
				商品详细描述:			
			</td>
			<td colspan="3">
			  <textarea name="goods_desc"></textarea>
			<script type="text/javascript" src="/program/plugins/ckeditor/ckeditor.js"></script>
			<script type="text/javascript">
				 //CKEDITOR.replace('goods_desc');
			   CKEDITOR.replace( 'goods_desc',{
			   	      filebrowserUploadUrl : '/program/inc/upload.jsp?type=file&attach_root_id=<%=goods_id%>',      
                filebrowserImageUploadUrl : '/program/inc/upload.jsp?type=img&attach_root_id=<%=goods_id%>',      
                filebrowserFlashUploadUrl : '/program/inc/upload.jsp?type=flash&attach_root_id=<%=goods_id%>'     
            });  
			</script>
			
			</td>
		</tr>      
      
     	<tr>
					<td  colspan="4">
				   &nbsp;&nbsp;<img src="/program/admin/images/infotip.gif" border="0">&nbsp;&nbsp;<span style="font-size:14px;font-weight:bold;">关联信息</span>			</td>
		    </tr>
 
      
         
     <tr>
			<td align="right" width="20%">
				同类商品:			
			</td>
			<td colspan="3">
        <select name="g_cat_id" id="g_cat_id">
        <option value="">所有分类</option>
         <%=s_cat_all%>									  
        </select>
			  <select name="g_brand_id" id="g_brand_id" >
				 <option value="">所有品牌</option>
				 <%=s_brand_all%>	
				</select>
				<input type="text" name="g_keyword" id="g_keyword"/>
				<input type="button" class="button_s_css" value=" 搜索 "  onclick="showLinkGoods('g')" />
			  
          <span id="g_goods_table"></span>       
        
			</td>
		</tr>  
		
		<tr>
			<td align="right" width="20%">
				推荐配饰:			
			</td>
			<td colspan="3">
        <select name="p_cat_id" id="p_cat_id">
        <option value="">所有分类</option>
         <%=s_cat_all%>									  
        </select>
			  <select name="p_brand_id" id="p_brand_id">
				 <option value="">所有品牌</option>
				 <%=s_brand_all%>	
				</select>
				<input type="text" name="p_keyword" id="p_keyword"/>
				<input type="button" class="button_s_css" value=" 搜索 " class="button" onclick="showLinkGoods('p')" />
			 
       			 
         <span id="p_goods_table"></span>  			 
			 
			</td>
		</tr>       
       
     
 	<tr>
			<td  colspan="4">
			   &nbsp;&nbsp;<img src="/program/admin/images/infotip.gif" border="0">&nbsp;&nbsp;<span style="font-size:14px;font-weight:bold;">其他信息</span>			</td>
	    </tr>
     
      <tr>
			<td align="right" width="20%">
				商家备注:			
			</td>
			<td colspan="3">
			  <textarea name="remark" id="remark" cols="55" rows="6" maxlength="200" onkeyup="return isMaxLen(this)" onBlur="return isMaxLen(this)"></textarea>			
			</td>
		</tr> 
 
    	
	</table>
	 	
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td align="center">
				<input type="hidden" name="bpm_id" value="5106" />
			  <input type="button" class="buttoncss" name="tradeSub" value="提交" onclick="subForm()"/>&nbsp;&nbsp;
				<input type="button" class="buttoncss" name="tradeRut" value="返回" onclick="window.location.href='index.jsp';"/>
			</td>
		</tr>
	</table>
	
	<input type="hidden" name="goods_id" id="goods_id" value="<%=goods_id%>">
	
    <input type="hidden" name="info_id" id="info_id" value="<%=goods_id%>">
	
	<input type="hidden" name="info_type" id="info_type" value="goods">
	
	<input type="hidden" name="class_attr" id="class_attr" value="<%=class_attr%>">
  
    <input type="hidden" name="state_code" id="state_code" value="af">
  
    <input type="hidden" name="attr_desc" id="attr_desc" value="">
                                                                 
	<input type="hidden" name="cust_id" id="cust_id" value="<%=cust_id%>">
                                                                        
   <input type="hidden" name="publish_user_id" id="publish_user_id" value="<%=publish_user_id%>">
                           
   <input type="hidden" name="link_goods" id="link_goods" value="">
  
   <input type="hidden" name="link_fit" id="link_fit" value="">
  
   <input type="hidden" name="member_price" id="member_price" value="">
  
   <input type="hidden" name="now_num" id="now_num" value="">

   <input type="hidden" name="before_num" id="before_num" value="0">
  
   <input type="hidden" name="vary_num" id="vary_num" value="0">
  
   <input type="hidden" name="vary_reason" id="vary_reason" value="新增商品库存初始">
 
  <input type="hidden" name="stock_flag" id="stock_flag" value="0">
  
  <input type="hidden" name="stock_method" id="stock_method" value="0">
  
  <input type="hidden" name="state_flag" id="state_flag" value="">
                                                                                                
	</form>

</body>

</html>
